home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2006 February / PCWFEB06.iso / Software / Resources / SyncBack Freeware 3.2.9 / SyncBack_Setup.exe / {app} / timestamp.vbs < prev   
Text File  |  2004-05-11  |  3KB  |  92 lines

  1. '------------------------------------------------------
  2. ' Add a timestamp to the start of the filename
  3. ' corresponding to the date the file was last changed.
  4. ' (Alter line starting "timestamp =" to alter the
  5. ' format of the timestamp that is prepended.)
  6. '
  7. ' (c) J.G.Clark 23.3.2004, with Functions from
  8. ' www.paulsadowski.com/WSH.
  9. '
  10. ' Modified by Michael J. Leaver (www.2BrightSparks.com)
  11. ' to concatenate arguments to avoid problems with
  12. ' spaces in filenames, display an error message if no
  13. ' filename was supplied, and also to copy the original
  14. ' file instead of moving it. This is to help its use
  15. ' with SyncBack (www.SyncBack.com)
  16. '
  17. ' Free for non-commerical use.
  18. '
  19. ' Run by calling "cscript timestamp.vbs <arg>"
  20. ' where <arg> is full path of file to filestamp.
  21. ' Works for UNC paths as well.
  22. '------------------------------------------------------
  23.  
  24. '------------------------------------------------------
  25. 'Return the pathname portion of a full pathname
  26. '------------------------------------------------------
  27. Function Pathname(FullPath)
  28. dim x, y
  29. dim tmpstring
  30.  
  31.   x = Len(FullPath)
  32.   for y = x to 1 step -1
  33.     if mid(FullPath, y, 1) = "\" or _
  34.       mid(FullPath, y, 1) = "/" then
  35.       tmpstring = mid(Fullpath, 1, y-1)
  36.       exit for
  37.     end if
  38. next
  39. Pathname = tmpstring
  40. end function
  41.  
  42. '------------------------------------------------------
  43. 'Return the filename portion of a full pathname
  44. '------------------------------------------------------
  45. Function Basename(FullPath)
  46. dim x, y
  47. dim tmpstring
  48.  
  49.   tmpstring = FullPath
  50.   x = Len(FullPath)
  51.   for y = x to 1 step -1
  52.     if mid(FullPath, y, 1) = "\" or _
  53.       mid(FullPath, y, 1) = ":" or _
  54.       mid(FullPath, y, 1) = "/" then
  55.       tmpstring = mid(Fullpath, y+1)
  56.       exit for
  57.     end if
  58.   next
  59. Basename = tmpstring
  60. end function
  61.  
  62. '------------------------------------------------------
  63. 'Main code
  64. '------------------------------------------------------
  65.  
  66. Set objArgs = WScript.Arguments
  67. Set fso = CreateObject("Scripting.FileSystemObject")
  68.  
  69. if (objArgs.Count < 1) then
  70.     WScript.Echo "No filename to copy was supplied."
  71. else
  72.     ' Concatenate all the arguments to create on filename
  73.     ' This is to avoid problems with spaces in filenames.
  74.     OldFilename = ""
  75.     for I = 0 to objArgs.Count - 1
  76.         OldFilename = OldFilename & objArgs.Item(I) & " "
  77.     Next
  78.     OldFilename = Trim(OldFilename)
  79.  
  80.     if fso.FileExists(OldFilename) = True then
  81.       Set f = fso.GetFile(OldFilename)
  82.       fc = f.DateLastModified
  83.       timestamp = Year(fc) & "-" & right("00" & Month(fc), 2) & "-" & right("00" & Day(fc), 2) & space(1) & right("00" & Hour(fc), 2) & right("00" & Minute(fc), 2) & space(1)
  84.       NewFilename = Pathname(OldFilename) & "\" & timestamp & Basename(OldFilename)
  85.       WScript.Echo NewFilename
  86.       fso.CopyFile OldFilename, NewFilename, True
  87.     else
  88.       WScript.Echo "File <" & OldFilename & "> not found"
  89.     end if
  90. end if
  91.  
  92.